package cn.wen.eeayjoke.ui;

import android.content.Intent;
import android.os.Bundle;

import com.wen.pay.PayPresenter;
import com.wen.pay.PayType;

import cn.wen.core.titlebar.DefTitleBar;
import cn.wen.core.ui.AppActivity;
import cn.wen.eeayjoke.R;

/**
 * 支付测试类
 */

public class PayTestActivity extends AppActivity {

    private PayPresenter mPayPresenter;

    @Override
    protected Object getContentLayout() {
        return R.layout.activity_pay;
    }

    @Override
    protected void initTitle(DefTitleBar titleBar) {
        titleBar.setTitle("微信支付宝支付测试");
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        mPayPresenter = new PayPresenter(this);
    }

    /**
     * 复写此方法
     */
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        if (mPayPresenter != null) {
            mPayPresenter.onNewIntent(intent);
        }
    }

    /**
     * 调起支付
     */
    public void pay() {
        // 后台请求回来的支付信息，如果没Base64加密，须将Base64解密方法去掉
        // 如果是微信支付就是预支付ID
        String payInfo = "";
        mPayPresenter.setOnPayListener(new PayPresenter.OnPayListener() {
            @Override
            public void onCompleted(PayType payType) {
                // 支付成功的回调
            }
        });
        // 这是发起支付宝支付
        mPayPresenter.alipay(payInfo);
        // 这是发起微信支付
        mPayPresenter.wxPay(payInfo);
    }
}
